<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jalur_model extends CI_Model{
	
	function get_jalur(){
		return $this->db->order_by("ID")
						->get("jalur_distribusi");
						
	}
	
	function tambah_jalur($data){
		var_dump($data);
		if(!isset($data["ID"])){
			return $this->db->query("
								insert into jalur_distribusi(NAMA,CATATAN,INDUK,TANGGAL_DIBUAT)
								values('".$data["NAMA"]."','".$data["CATATAN"]."',".$data["INDUK"].",now())
			");
		} else {
			//var_dump($data);
			return $this->db->insert("jalur_distribusi", $data);
		}
		
	}
	
	function get_max(){
		return $this->db->select_max("ID")
						->get("jalur_distribusi");
	}
	
	
	function ganti_id($max,$data){
		$id = (int)$data["INDUK"];
		for($max; $max>$id; $max--){
			$this->db->where("ID", $max)
					 ->set("ID",$max+1)
					 ->update("jalur_distribusi");
					 
		}
		
		$data["ID"] = $id+1;
		if($this->tambah_jalur($data)){
			return true;
		} else {
			return false;
		}
	}
	
	function delete_jalur($id){
		return $this->db->where("ID", $id)
						->delete("jalur_distribusi");
	}
}